<template>
    <el-container>
    <el-main>
      <el-table :data="tableData" >
        <el-table-column  label="序号" width="100">
            <template slot-scope="scope">
            {{scope.$index+1}} 
          </template>
        </el-table-column>
        <el-table-column prop="fir_name" label="固件名称">
        </el-table-column>
        <el-table-column
         prop="username"
          label="用户名"
          :filters="userFilter"
            :filter-method="filterUser">
        </el-table-column>
        <el-table-column prop="product_name" label="所属项目">
        </el-table-column>
        
        <el-table-column prop="desc" label="备注" >
        </el-table-column>
        <el-table-column prop="version" label="版本号">
        </el-table-column>
        <el-table-column prop="count" label="升级数量">
        </el-table-column>
        <el-table-column  prop="text" fixed="right" label="操作" >
            <el-button type="text" size="small" @click="getFile">导出设备列表</el-button>

        </el-table-column>
      </el-table>
    </el-main>
     </el-container>
</template>

<script>
  import {Axios} from "../../../static/util";
  const axios =  require('axios');
    export default {
        name:"us",
        methods: {
            filterUser(value, row){
              return row.name === value;
            },
            getFile(){
               	axios.get('http://127.0.0.1:5000/output_device_list?get_time'+new Date().getTime(), {
                    responseType: 'blob',
                    headers:{ Authorization:'JWT '+this.$cookies.get('_token')}
                }).then((res) => {
                    if (res.status===200) {
                        var elink = document.createElement('a');
                        elink.download = 'imei.csv';
                        elink.style.display = 'none';
                        elink.href = window.URL.createObjectURL(new Blob([res.data],{type:'text/csv'}));
                        elink.click();
                        this.$message({
                            type: 'success',
                            message: '数据导出成功'
                        });
                    }
                })
                .catch((err) => {
                    this.$message.error(`数据导出失败，${err.message}`);
                });

            },


        },
         data(){
            
            return {
                tableData: [],
                serch: '',
                datestart: '',
                dateend: "",
                userFilter:[],
            };
        },
        created(){

             let self = this;
            Axios(
              'get',
              'http://127.0.0.1:5000/firmware_statistics',
              {},
              (res)=>{
              if (res.data.code != "200"){
                  this.$message.warning('错误:'+res.data.msg);
                  
              }else{
                this.tableData = res.data.data;
                
              }
                
            });
           
            let ary = [];

             this.tableData.forEach(item => {
              if(ary.indexOf(item.name) == -1){
                 self.userFilter.push({
                  text:item.name,
                  value:item.name
                 });
                 ary.push(item.name);
              }
            });
        }

    }
</script>

<style>
</style>
